<?php
namespace StarCloud\Library;

class AppRequest
{
    public static function getIp(): string
    {
        $ip = $_SERVER['HTTP_CF_CONNECTING_IP'] ?? $_SERVER['HTTP_X_FORWARDED_FOR'] ?? '';
        if (empty($ip) && ENVIRONMENT != 'production') {
            $ip = $_SERVER['REMOTE_ADDR'] ?? '';
        }

        return $ip;
    }

    public static function getAppPlatform(): string
    {
        if (strpos(strtolower($_SERVER['HTTP_USER_AGENT'] ?? ''), 'android') !== false) {
            return 'android';
        }

        return 'ios';
    }

    public static function getAppVersion(): string
    {
        return $_REQUEST['app_version'] ?? '';
    }

    public static function getAppChannel(): string
    {
        return $_REQUEST['app_channel'] ?? '';
    }

    public static function isProVersion(): bool
    {
        return !self::isGpVersion();
    }

    public static function isGpVersion(): bool
    {
        return self::getAppChannel() == 'googleplay';
    }

    public static function getShumeiDeviceId(): string
    {
        return $_REQUEST['shumei_device_id'] ?? '';
    }
}
